package user

import (
	login "AI/Services/Login"
	recharge "AI/Services/recharge"
	route "AI/router"
	userFunc "AI/services/user"
	status "AI/util"
	"database/sql"
	"encoding/json"
	"net/http"

	"github.com/gin-gonic/gin"
	_ "github.com/go-sql-driver/mysql"
)

var db *sql.DB

func init() {
	route.Register(&User{})
}

type User struct {
}
type Login struct {
	Account string
	pws     string
}

func (api *User) Pages_get(c *gin.Context) {
	//api.httpMethod="GET"
	// users := []int{1,2,3}
	status, _ := c.Get("status")
	if status == 401 {
		c.JSON(http.StatusOK, gin.H{
			"code": status,
			"msg":  "ok",
			"data": "未登录",
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code":     1,
		"msg":      "ok",
		"data":     "成功",
		"username": "123",
	})

}

// 登录
func (api *User) Login(c *gin.Context) {
	Data := make(map[string]string)
	json.NewDecoder(c.Request.Body).Decode(&Data)
	login.PasOrAccount(Data, c)
}

// 注册
func (api *User) Registered(c *gin.Context) {
	Data := make(map[string]string)
	json.NewDecoder(c.Request.Body).Decode(&Data)
	login.Registered(Data, c)
}

// 获取余额
func (api *User) Balance(c *gin.Context) {
	s := status.Islogin(c)
	if !s {
		return
	}
	Data := make(map[string]string)
	json.NewDecoder(c.Request.Body).Decode(&Data)
	login.Getbalance(Data, c)
}

// 获取充值套餐内
func (api *User) Getpackage(c *gin.Context) {
	recharge.GetPackage(c)
}

// 修改用户名称 传参 Token,NewName
func (api *User) SetUseName(c *gin.Context) {
	userFunc.SetUseName(c)
}

// 获取充值记录 type
func (api *User) Getbalancelist(c *gin.Context) {
	//
}

// 获取好友列表
func (api *User) GetFriends(c *gin.Context) {
	/*
	 *get 传入Token UserId 查询表
	 */
}

// 修改用户头像
func (api *User) SetUserImg(c *gin.Context) {
	/*
	 *Post 传入Image地址查询表 =>修改头像
	 */
	userFunc.SetImage(c)
}
